package org.jeecg.modules.app.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.api.announcement.entity.Announcement;
import org.jeecg.modules.api.announcement.service.IAnnouncementService;
import org.jeecg.modules.api.member.entity.Member;
import org.jeecg.modules.api.member.service.IMemberService;
import org.jeecg.modules.app.service.IIndexService;
import org.jeecg.modules.app.service.IWeChatService;
import org.jeecg.modules.app.vo.IndexVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description: 首页信息
 * @author: Young Jun
 * @date: 2024年09月20日 9:57
 */
@Api(tags="小程序首页")
@RestController
@RequestMapping("/app/index")
@Slf4j
public class IndexController {

    @Resource
    private IIndexService indexService;
    @Autowired
    private IAnnouncementService announcementService;
    @Autowired
    private IMemberService memberService;
    @GetMapping()
    @ApiOperation(value = "小程序首页数据", notes = "小程序首页数据")
    public Result<IndexVo> getIndex() {
        return Result.OK(indexService.getIndex());
    }

    @GetMapping("/getAnnouncement")
    @ApiOperation(value = "公告、协议的、等级接口", notes = "公告、协议的、等级")
    public Result<IPage<Announcement>> getAnnouncement(
            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
            @RequestParam(name="type", defaultValue="0") Integer type,
            @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
        log.info("getAnnouncement:{}",type);
        return Result.OK(indexService.getAnnouncement(type,pageNo, pageSize));
    }
    @GetMapping("/getAnnouncementById")
    public Result<Announcement> getAnnouncement(@RequestParam(name="id",required = false) String id) {
        if (id != null) {
            return Result.OK(announcementService.getById(id));
        } else {
            return Result.OK(announcementService.getOne(new LambdaQueryWrapper<Announcement>()
                    .eq(Announcement::getIsDisplay, 1)
                    .last("limit 1")));
        }
    }
}
